﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views {
    import flash.events.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.views.components.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.controllers.startup.*;
    import net.wooga.pets.services.*;

    public class GameViewOptionsMediator extends Mediator {

		[Inject]
        public var gameViewOptionsMenu:GameViewOptionsMenu;
		[Inject]
        public var gameStateModel:GameStateModel;
		[Inject]
        public var tutorialModel:TutorialModel;
		[Inject]
        public var gameViewModel:GameViewModel;
		[Inject]
        public var soundService:SoundService;

        override public function onRegister():void{
            eventMap.mapListener(eventDispatcher, GameEvent.TUTORIAL_STATE_CHANGE, this.tutorialStateChange);
            eventMap.mapListener(eventDispatcher, BuildingEvent.FACADE_CHANGED, this.facadeChanged);
            eventMap.mapListener(eventDispatcher, EventConstants.EFFECT_SOUND_STATE_CHANGE, this.soundStateChange);
            eventMap.mapListener(eventDispatcher, EventConstants.MUSIC_SOUND_STATE_CHANGE, this.musicStateChange);
            eventMap.mapListener(this.gameViewOptionsMenu.zoomInButton, MouseEvent.CLICK, this.zoomInButton_click);
            eventMap.mapListener(this.gameViewOptionsMenu.zoomOutButton, MouseEvent.CLICK, this.zoomOutButton_click);
            eventMap.mapListener(this.gameViewOptionsMenu.facadeButton, MouseEvent.CLICK, this.facadeButton_click);
            eventMap.mapListener(this.gameViewOptionsMenu.soundEffectsButton, MouseEvent.CLICK, this.soundEffectsButton_click);
            eventMap.mapListener(this.gameViewOptionsMenu.musicButton, MouseEvent.CLICK, this.musicButton_click);
            this.updateSoundEffectsButton();
            this.updateMusicButton();
        }
        private function musicStateChange(_arg1:Event):void{
            this.updateMusicButton();
        }
        private function soundStateChange(_arg1:Event=null):void{
            this.updateSoundEffectsButton();
        }
        private function updateSoundEffectsButton():void{
            this.gameViewOptionsMenu.soundEffectsButton.selected = this.soundService.effectsMuted;
        }
        private function updateMusicButton():void{
            this.gameViewOptionsMenu.musicButton.selected = this.soundService.musicMuted;
        }
        private function facadeChanged(_arg1:BuildingEvent):void{
            this.gameViewOptionsMenu.toggleFacadeButton(this.gameStateModel.isFacadeVisible);
        }
        private function tutorialStateChange(_arg1:GameEvent):void{
            if (this.tutorialModel.state < TutorialModel.END){
                this.gameViewOptionsMenu.hide();
            } else {
                this.gameViewOptionsMenu.show();
            };
        }
        private function zoomInButton_click(_arg1:MouseEvent):void{
            this.gameViewModel.increaseScaleFactor(false);
        }
        private function zoomOutButton_click(_arg1:MouseEvent):void{
            this.gameViewModel.decreaseScaleFactor(false);
        }
        private function facadeButton_click(_arg1:Event):void{
            var _local2:Object = {type:"interface", subtype1:"toggle"};
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.EVENT, _local2));
            this.gameStateModel.isFacadeVisible = !(this.gameStateModel.isFacadeVisible);
        }
        private function soundEffectsButton_click(_arg1:Event):void{
            this.soundService.effectsMuted = !(this.soundService.effectsMuted);
            this.sendSoundState();
            var _local2:String = (this.soundService.effectsMuted) ? "off" : "on";
            this.track("sound", _local2);
        }
        private function musicButton_click(_arg1:MouseEvent):void{
            this.soundService.musicMuted = !(this.soundService.musicMuted);
            this.sendSoundState();
            var _local2:String = (this.soundService.musicMuted) ? "off" : "on";
            this.track("music", _local2);
        }
        private function sendSoundState():void{
            dispatch(new Event(EventConstants.SEND_SOUND_STATE));
        }
        private function track(_arg1:String, _arg2:String):void{
            var _local3:Object = new Object();
            _local3.type = "interface";
            _local3.st1 = _arg1;
            _local3.st2 = _arg2;
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.EVENT, _local3));
        }

    }
}//package net.wooga.pets.views 
